package com.smashcrush.client.gwt.util;

import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;

public abstract class WidgetUtil {

	public static Label createLabel(String name) {
		Label lbl = new Label(name);
		lbl.setWidth("150px");
		return lbl;
	}

	public static void setListBoxValue(ListBox box, String value) {
		int index = 0;

		for (int i = 0; i < box.getItemCount(); i++) {
			String val = box.getValue(i);
			if (val.equals(value)) {
				index = i;
				break;
			}
		}

		box.setSelectedIndex(index);
	}

	public static String getListBoxValue(ListBox box) {
		return box.getValue(box.getSelectedIndex());
	}

	public static DecoratorPanel decorate(Widget w, String width, String height) {
		DecoratorPanel dp = new DecoratorPanel();
		dp.setSize(width, height);
		dp.add(w);
		return dp;
	}

}
